﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace KeDa2025_
{
    /// <summary>
    /// DelCommentHandler 的摘要说明
    /// </summary>
    public class DelCommentHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
           
                int commentId = Convert.ToInt32(context.Request["cid"]);
                string connectionString = "server=localhost;user id=zmy2;password=zmy20020525;database=forum;";
                try
                {
                    using (MySqlConnection conn = new MySqlConnection(connectionString))
                    {
                        conn.Open();
                        string sql = "DELETE FROM comments WHERE id = @CommentId";
                        using (MySqlCommand cmd = new MySqlCommand(sql, conn))
                        {
                            cmd.Parameters.AddWithValue("@CommentId", commentId);
                            int rows = cmd.ExecuteNonQuery();
                            context.Response.ContentType = "text/plain";
                            context.Response.Write(rows > 0 ? "true" : "false");
                        }
                    }
                }
                catch (Exception ex)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("false");
                }
            }


    

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}